package com.wx.day01.ioc1;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;

import javax.sql.DataSource;
import java.sql.PreparedStatement;

public class UserDao {
    private DruidDataSource dataSource;
    public void setDataSource(DruidDataSource dataSource) {
        this.dataSource = dataSource;
    }
    public void insert() throws Exception{
        DruidPooledConnection conn = dataSource.getConnection();
        String sql = "insert into account (name, money) values (?, ?)";
        PreparedStatement pstmt = conn.prepareStatement(sql);
        pstmt.setString(1, "sxxxx");
        pstmt.setInt(2, 10022);
        int st = pstmt.executeUpdate();
        if(st>0){
            System.out.println("Success connect database insert ok!");
        }
        pstmt.close();
        conn.close();
    }
}
